package com.a2.appa3.ui.activity;

import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;

import com.a2.appa3.R;
import com.a2.appa3.global.Info;
import com.a2.appa3.util.SpUtils;

import butterknife.BindView;
import me.shihao.library.XStatusBarHelper;

public class NewMessageActivity extends BaseActivitySimple {

    @BindView(R.id.ivback)
    ImageView ivback;
    @BindView(R.id.back)
    LinearLayout back;
    @BindView(R.id.headerTitle)
    TextView headerTitle;
    @BindView(R.id.headerButton)
    ImageView headerButton;
    @BindView(R.id.headerButtonRoot)
    LinearLayout headerButtonRoot;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.appbar)
    AppBarLayout appbar;
    @BindView(R.id.voiceswich)
    Switch voiceswich;
    @BindView(R.id.voicelayout)
    RelativeLayout voicelayout;
    @BindView(R.id.shockswich)
    Switch shockswich;
    @BindView(R.id.shocklayout)
    RelativeLayout shocklayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= 21) {
            //解决Android5.0以上，状态栏设置颜色后变灰的问题
            XStatusBarHelper.tintStatusBar(this, getResources().getColor(R.color.settingbg));
        }
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        headerTitle.setText("新消息提醒");
        if (SpUtils.getBoolean(NewMessageActivity.this, "voiceswich")) {
            voiceswich.setChecked(true);
            Info.voiceflag = true;
        } else {
            voiceswich.setChecked(false);
            Info.voiceflag = false;
        }
        if (SpUtils.getBoolean(NewMessageActivity.this, "shockswich")) {
            Info.shockflag = true;
            shockswich.setChecked(true);
        } else {
            Info.shockflag = false;
            shockswich.setChecked(false);
        }


        voiceswich.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    Info.voiceflag = true;
                    SpUtils.putBoolean(NewMessageActivity.this, "voiceswich", true);
                } else {
                    Info.voiceflag = false;
                    SpUtils.putBoolean(NewMessageActivity.this, "voiceswich", false);
                }
            }
        });
        shockswich.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    Info.shockflag = true;
                    SpUtils.putBoolean(NewMessageActivity.this, "shockswich", true);
                } else {
                    SpUtils.putBoolean(NewMessageActivity.this, "shockswich", false);
                    Info.shockflag = false;
                }
            }
        });
    }

    @Override
    protected int setContentView() {
        return R.layout.activity_new_message;
    }
}
